<template>
  <div class="page">
    <navigation>{{ $t('昵称') }}</navigation>
    <div class="info-form">
      <div class="info-item">
        <input v-model="nickname" type="text" class="value" :placeholder="$t('昵称')">
      </div>
      <div class="tip">{{ $t('请填写修改后的昵称(3-12个字)') }}</div>
    </div>
    <button class="confirm-btn" :disabled="nickname.length==0" @click="handleChange">{{ $t('确认修改') }}</button>
  </div>
</template>
<script>
import { mapActions } from 'vuex'
import { Toast } from 'mint-ui'
import navigation from '@/components/Navigation'
export default {
  components: { navigation },
  data () {
    return {
      nickname: ''
    }
  },
  methods: {
    ...mapActions({
      editUserInfo: 'auth/editUserInfo'
    }),
    handleChange () {
      const payload = {
        nickname: this.nickname
      }
      this.editUserInfo(payload)
        .then((data) => {
          Toast(data.message)
          this.$router.back()
        })
        .catch((error) => {
          Toast(error.message)
        })
    }
  }
}
</script>
<style scoped>
.page {
  padding-top: 90px;
}
.info-form {
  border-top: 1px solid #eee;
}
.info-item {
  padding: 0 15px;
  height: 48px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.info-item .value {
  flex-grow: 1;
  line-height: 28px;
  padding: 10px 0;
  font-size: 15px;
}
.tip {
  padding: 10px 15px;
  font-size: 12px;
  color: #666666;
}
.confirm-btn {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40px;
  line-height: 40px;
  background: #1b8afe;
  color: #ffffff;
  font-size: 16px;
  letter-spacing: 2px;
}
.confirm-btn:disabled {
  opacity: .8;
  cursor: default;
}
</style>
